package com.zork.cmdb.webapi.service.impl;

import com.zork.cmdb.webapi.common.exception.CmdbException;
import com.zork.cmdb.webapi.common.exception.CmdbModuleNotFoundException;
import com.zork.cmdb.webapi.domain.dto.ModuleAttributesDTO;
import com.zork.cmdb.webapi.domain.vo.ModuleAttributesVO;
import com.zork.cmdb.webapi.mapper.cmdb.ModuleAttributesMapper;
import com.zork.cmdb.webapi.service.ModuleAttributesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author chenjh
 * @date 2018/5/15
 * @description
 */
@Service
public class ModuleAttributesServiceImpl implements ModuleAttributesService {

    @Autowired
    private ModuleAttributesMapper moduleAttributesMapper;

    @Override
    public List<ModuleAttributesVO> listAttributes(Integer moduleID) throws CmdbException {
        List<ModuleAttributesDTO> moduleAttributesDTOList = moduleAttributesMapper.listAttributes(moduleID);
        if (moduleAttributesDTOList == null || moduleAttributesDTOList.size() == 0) {
            throw new CmdbModuleNotFoundException();
        }
        List<ModuleAttributesVO> moduleAttributesVOList = com.zork.cmdb.webapi.domain.mapper.ModuleAttributesMapper.MAPPER.getVOList(moduleAttributesDTOList);
        return moduleAttributesVOList;
    }
}
